package com.hzj.recipe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzj.recipe.entity.Enjoy;
import com.hzj.recipe.entity.Enjoy;
import com.hzj.recipe.mapper.EnjoyMapper;
import com.hzj.recipe.service.EnjoyService;
import com.hzj.recipe.mapper.EnjoyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
* @author 蜗牛菌
* @description 针对表【enjoy(用户喜欢表)】的数据库操作Service实现
* @createDate 2024-01-04 10:49:47
*/
@Service
public class EnjoyServiceImpl extends ServiceImpl<EnjoyMapper, Enjoy>
    implements EnjoyService{

    @Autowired
    private EnjoyMapper enjoyMapper;
    
    @Override
    public Object listAll(Integer index, Integer size, Enjoy enjoy) {
        //默认第一页开始，每页5条
        if(index == null ||index==0){
            index=1;
        }
        if(size==null||size==0){
            size=5;
        }
        Page<Enjoy> pageInfo = new Page(index, size);
        LambdaQueryWrapper<Enjoy> lambdaQueryWrapper = new LambdaQueryWrapper();
        if (enjoy.getEnjoyId() != null && enjoy.getEnjoyId() != 0 && !Objects.equals(enjoy.getEnjoyId(), "")) {
            lambdaQueryWrapper.eq(Enjoy::getEnjoyId, enjoy.getEnjoyId());
        }
        if (enjoy.getUserId() != null && enjoy.getUserId() != 0 && !Objects.equals(enjoy.getUserId(), "")) {
            lambdaQueryWrapper.eq(Enjoy::getUserId, enjoy.getUserId());
        }
        if (enjoy.getRecipeId() != null && enjoy.getRecipeId() != 0 && !Objects.equals(enjoy.getRecipeId(), "")) {
            lambdaQueryWrapper.eq(Enjoy::getRecipeId, enjoy.getRecipeId());
        }

        Page<Enjoy> enjoyPage = enjoyMapper.selectPage(pageInfo, lambdaQueryWrapper);

        return enjoyPage;
    }
}




